/**
 * @author liubaohui
 * @deprecated 已修改为后端过滤
 * @desc 任务号搜索
 * @type {{methods: {handleSearch(): (undefined|*)}}}
 */
let taskBomTreeSearch = {
  methods: {
    handleSearch() {
      if (this.keyword === '') return
      let nodesMap = this.$refs.elTree.store.nodesMap
      if (!nodesMap.hasOwnProperty(this.keyword)) {
        return this.$message.error({
          message: '未搜索到该任务号',
          duration: 1500,
          center: true
        })
      }
      let node = nodesMap[this.keyword.toUpperCase()]
      // level = 2的是任务号
      if (node.level !== 2) {
        return this.$message.error({
          message: '未搜索到该任务号',
          duration: 1500,
          center: true
        })
      }
      // 设置高亮并展开任务号的父节点
      this.$refs.elTree.setCurrentNode(node)
      node.parent.expanded = true
      let timer = setInterval(() => {
        let elLabelList = this.$refs.elTree.$el.getElementsByClassName('el-tree-node__label')
        let el = Array.from(elLabelList).find(label => {
          return label.innerText.split('/')[0] === this.keyword.toUpperCase()
        })
        let clientHeight = this.$refs.elTree.$el.clientHeight
        if (this.treeClientHeight === clientHeight) {
          this.$nextTick(() => {
            this.$refs.scrollbar.$refs.wrap.scrollTop = el.offsetTop - 4
          })
          return clearInterval(timer)
        }
        this.treeClientHeight = clientHeight
      }, 50)
      this.$emit('selectNode', this.keyword.toUpperCase(), [])
    },
  }
}

export default taskBomTreeSearch
